package com.jari.lg.service.profile.device;

import com.jari.lg.domain.CrossBase;
import com.jari.lg.domain.DevBase;
import com.jari.lg.domain.DeverrQuarterHisEntity;
import com.jari.lg.mapper.DeverrQuarterHisEntityMapper;
import com.jari.lg.mapper.DeverrRtEntityMapper;
import com.jari.lg.utils.BaseData;
import com.jari.lg.utils.Utils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeverrQuarterHisService {

    @Autowired
    private DeverrQuarterHisEntityMapper deverrQuarterHisEntityMapper;

    /*
    *   每天只造一千条
    * */
    public void makeInfo(){
        DeverrQuarterHisEntity entity;
        List<DevBase> devBases = BaseData.devBaseList;
        List<CrossBase> crossBaseList = BaseData.crossBaseList;
        for(int i = 0 ; i < 1000 ; i ++){
            entity = generate(devBases.get(Utils.makeRandInt(devBases.size())), crossBaseList);
            if(null != entity){
                deverrQuarterHisEntityMapper.insert(entity);
            }
        }
    }

    private DeverrQuarterHisEntity generate(DevBase devBase,List<CrossBase> crossBaseList){
        DeverrQuarterHisEntity entity = new DeverrQuarterHisEntity();
        if(StringUtils.isNotBlank(devBase.getCrosscode())){
                entity.setLatitude(crossBaseList.stream().filter(x -> x.getCrosscode().equals(devBase.getCrosscode())).findFirst().get().getCrosslat().doubleValue());
                entity.setLongitude(crossBaseList.stream().filter(x -> x.getCrosscode().equals(devBase.getCrosscode())).findFirst().get().getCrosslon().doubleValue());

        }else if (StringUtils.isNotBlank(devBase.getKeyareagate())){
            entity.setLatitude(crossBaseList.stream().filter(x -> x.getCrosscode().equals(devBase.getKeyareagate())).findFirst().get().getCrosslat().doubleValue());
            entity.setLongitude(crossBaseList.stream().filter(x -> x.getCrosscode().equals(devBase.getKeyareagate())).findFirst().get().getCrosslon().doubleValue());

        }else {
            return null;
        }
        entity.setDevname(devBase.getDevicename());
        entity.setDevcode(devBase.getDevicecode());
        entity.setDevtype(devBase.getDevicetype());
        return entity;
    }

}
